package gameUtils;

import gameExceptions.*;

public class Stack {
	public int size;
	public StackNode topEntity;
	
	public boolean isEmpty(){
		return ((size == 0) && topEntity == null)?true:false;
	}
	
	public void push(StackNode newTopEntity){
		newTopEntity.setNextNode(topEntity);
		this.topEntity = newTopEntity;
		size++;
	}
	
	public StackNode peek() throws EmptyStackException{
		if(this.isEmpty()){
			throw new EmptyStackException();
		}
		return topEntity;
	}
	public StackNode pop() throws EmptyStackException{
		if(this.isEmpty()){
			throw new EmptyStackException();
		}
		StackNode temp = topEntity;
		this.topEntity = topEntity.getNextNode();
		temp.setNextNode(null);
		size--;
		return temp;
	}
	public void clearStack(){
		size = 0;
		topEntity = null;
	}
	
	public String toString(){
		return "Size: " +size+"; First Item: "+topEntity.toString();
	}
	
	public Stack(){
		this.size = 0;
		this.topEntity = null;
	}
	
}
